package com.lqr.util;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidPooledConnection;
import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.sql.Connection;

public class SpringTest {
    @Test
    public void test(){
        ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring.xml");
        Object u1 = applicationContext.getBean("u1");
        System.out.println(u1);
        applicationContext.close();
    }

    @Test
    public void druid() throws Exception {
        //使用无参构造方法创建druid连接池对象
        DruidDataSource dataSource=new DruidDataSource();
        //使用对应的set方法进行连接池的属性配置
        dataSource.setDriverClassName("com.mysql.jdbc.Driver");
        dataSource.setUrl("jdbc:mysql://localhost:3306/test");
        dataSource.setUsername("root");
        dataSource.setPassword("123456");
        //使用连接池获取连接
        DruidPooledConnection connection = dataSource.getConnection();
        System.out.println(connection);
        //归还连接至连接池 关闭连接池
        connection.close();
        dataSource.close();

    }
    @Test
    public void c3p0() throws Exception {
        //使用无参构造方法创建c3p0连接池对象
        ComboPooledDataSource dataSource=new ComboPooledDataSource();
        //使用对应的set方法进行连接池的属性配置
        dataSource.setDriverClass("com.mysql.jdbc.Driver");
        dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/test");
        dataSource.setUser("root");
        dataSource.setPassword("123456");
        //使用连接池获取连接
        Connection connection = dataSource.getConnection();
        System.out.println(connection);
        //归还连接至连接池 关闭连接池
        connection.close();
        dataSource.close();
    }
    @Test
    public void u1(){
        ClassPathXmlApplicationContext applicationContext=new ClassPathXmlApplicationContext("spring.xml");
}